<?php
	/**
	 * Funkcja obslugujaca bledy systemu.
	 *
	 * @param int $errNo
	 * @param str $errStr
	 * @param str $errFile
	 * @param int $errLine
	 * @return mixed
	 */
	function error_handler($errNo, $errStr, $errFile, $errLine){
		$errFile = str_replace(SYS_PATH, '', $errFile);

		if(!isset($_SESSION['user_id']) || $_SESSION['user_id'] != 'test'){
			if(($errNo == 2 && !LOCAL) || $errNo == 8 || $errNo == 4 || $errNo == 8192)
				return 1;
		}

		if($errNo == 8 || $errNo == 2048)
			return 1;

		$error_message = "<br /> \n <b>W pliku: </b>" . $errFile .
						 "<b>, w linii nr</b> ". $errLine .
						 "<br /> \n <b>Wystąpił błąd:</b> " . $errStr.
						 "<br /> \n <b>Nr błędu:</b> ".$errNo;


		include SYS_PATH.'tpl'.SEPARATOR.'error_page.tpl';

		if(@mysql_ping()){
			$number = mysql_real_escape_string($errNo);
			$error = mysql_real_escape_string($errStr);
			$file = mysql_real_escape_string($errFile);
			$line = mysql_real_escape_string($errLine);
			$time = date("Y.m.d H:i:s");
			if(isset($_SESSION['user_id']) && $_SESSION['user_id'] != ""){
				$user = $_SESSION['user_id'];
				$query = "INSERT INTO tbl_errors(number, error, file, line, time, user_id)
						  VALUES ('$number','$error','$file','$line','$time',$user)";
			}
			else{
				$query = "INSERT INTO tbl_errors(number, error, file, line, time)
						  VALUES ('$number','$error','$file','$line','$time')";
			}
			mysql_query($query);
		}

		die();
	}
?>